﻿using System;
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Security.Cryptography;
using System.Web.UI.WebControls.WebParts;
using System.Security.Cryptography;
using System.Text;

/// Summary description for mahoa
/// </summary>
public class mahoa
{
    public string mahoamk(string matkhau, bool ues)
    {
        byte[] keyArry;
        byte[] toEncryArry = UTF8Encoding.UTF8.GetBytes(matkhau);
        if (ues)
        {

            MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
            keyArry = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes("nhox"));

        }
        else keyArry = UTF8Encoding.UTF8.GetBytes("nhox");
        TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
        tdes.Key = keyArry;
        tdes.Mode = CipherMode.ECB;
        tdes.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTranfrom = tdes.CreateEncryptor();
        byte[] kq = cTranfrom.TransformFinalBlock(toEncryArry, 0, toEncryArry.Length);
        return Convert.ToBase64String(kq, 0, kq.Length);


    }


    public string giamamk(string matkhau, bool ues)
    {
        byte[] keyArry;
        byte[] toEncryArry = Convert.FromBase64String(matkhau);
        if (ues)
        {
            MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
            keyArry = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes("nhox"));


        }
        else

            keyArry = UTF8Encoding.UTF8.GetBytes("nhox");
        TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
        tdes.Key = keyArry;
        tdes.Mode = CipherMode.ECB;
        tdes.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTranfrom = tdes.CreateEncryptor();
        byte[] kq = cTranfrom.TransformFinalBlock(toEncryArry, 0, toEncryArry.Length);
        return UTF8Encoding.UTF8.GetString(kq);


    }
}
